package com.eric.demo.alibishi;

import java.io.File;
import java.util.Arrays;

/**
 * @author guangyin.zhang
 * @since 2020/4/2
 */
public class PrintFile {

    public static void main(String[] args){
        PrintFile printFile = new PrintFile();
        String path1 = "E:\\test";
        File file = new File(path1);
        printFile.print(file, 0);

    }

    void print(File file, int k){
        if(file.exists()){
            if(file.isDirectory()){
                File[] files = file.listFiles();
                if(files != null && files.length > 0){
                    Arrays.stream(files).forEach(t-> print(t, k+1));
                } else {
                    printName(k, file.getName());
                }
            }else{
                printName(k, file.getName());
            }
        }

    }

    void printName(int k, String name){
        for(int i=0; i< k; i++){
            System.out.print("  ");
        }
        System.out.println(name);
    }
}
